<template>
    <div style="height: 100%; width: 100%; position: relative">
        <div :class="!is_showselother ? 'pagetop' : 'pagetopother'">
            <div style="height: 100%;width: 100%;">
                <table border="0" style=" font-size: 12px; white-space: nowrap">
                    <tr>
                        <td align="right">
                            <el-dropdown @command="handleCommand" style="font-size: 12px">
                                <u class="el-dropdown-link">
                                    {{ datename }}
                                </u>
                                <el-dropdown-menu slot="dropdown">
                                    <el-dropdown-item command="标本日期">
                                        <font font-size="12px">标本日期</font>
                                    </el-dropdown-item>
                                    <el-dropdown-item command="报告日期">
                                        <font font-size="12px">报告日期</font>
                                    </el-dropdown-item>
                                </el-dropdown-menu>
                            </el-dropdown>
                        </td>
                        <td>
                            <table style="border-spacing:0px">
                                <tr>
                                    <td>
                                        <el-date-picker v-model="searchobj.strdate" :clearable="false" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" style="width: 125px"> </el-date-picker>
                                    </td>
                                    <td>至</td>
                                    <td>
                                        <el-date-picker v-model="searchobj.enddate" type="date" :clearable="false" placeholder="选择日期" value-format="yyyy-MM-dd" style="width: 125px"> </el-date-picker>
                                    </td>
                                </tr>
                            </table>
                        </td>
                        <td align="right">菌属</td>
                        <td>
                            <rm-ddl-common datatype="germgroup" dataname="菌属(三级分类)" v-model="searchobj.germgroup" width="150px" :appendtobody="true" key="dialoggroupitemcode" readonly @change="germgroupChange"></rm-ddl-common>
                        </td>
                        <td align="right">菌科</td>
                        <td>
                            <rm-ddl-common datatype="labgermkind" dataname="菌科(二级分类)" v-model="searchobj.germkind" width="150px" :appendtobody="true" key="dialoggermkind" @change="germkindChange"></rm-ddl-common>
                        </td>
                        <td align="right">细菌</td>
                        <td>
                            <el-select v-model="searchobj.germrptitemcode" @dblclick.native="popMultipleChk(searchobj.germrptitemcode, 'germrptitemcode', germOption, '请选择细菌')" filterable clearable style="width:150px">
                                <el-option v-for="(item, index) in germOption" :key="index" :value="item.data" :label="item.display"></el-option>
                            </el-select>
                        </td>
                        <td>数值结果</td>
                        <td>
                            &lt; <el-input size="small" style="width:45px" v-model="searchobj.result_min" oninput="value=value.replace(/[^\-?\d.]/g,'')"></el-input>
                            数值结果&gt;<el-input size="small" style="width:47px" v-model="searchobj.result_max" oninput="value=value.replace(/[^\-?\d.]/g,'')"></el-input>
                        </td>
                        <td colspan="2" align="center">
                            <!--包含药敏即为只查药敏-->
                            <el-checkbox true-label="1" false-label="0" v-model="searchobj.onlyposresult">包含药敏</el-checkbox>
                            &nbsp;&nbsp;
                            <el-link :underline="false" @click="btn_showselother">{{ is_showselother ? "收起其它条件" : "展开其它条件" }}<i :class="is_showselother ? 'el-icon-caret-top' : 'el-icon-caret-bottom'"></i> </el-link>
                        </td>
                    </tr>
                    <tr v-show="is_showselother">
                        <td align="right">标本号</td>
                        <td>
                            <el-input v-model="searchobj.txtbarcode" @keyup.enter.native="FunQuery" style="width: 260px" clearable @keyup.native.enter="BtnQuery"></el-input>
                        </td>
                        <td align="right">科室</td>
                        <td>
                            <el-select v-model="searchobj.reqdept" @dblclick.native="popMultipleChk(searchobj.reqdept, 'reqdept', deptOption, '申请科室选择')" filterable clearable style="width:150px">
                                <el-option v-for="(item, index) in deptOption" :key="index" :value="item.data" :label="item.display"> </el-option>
                            </el-select>
                        </td>
                        <td align="right">病历号</td>
                        <td>
                            <el-input v-model="searchobj.txtpatno" clearable style="width:150px" @keyup.native.enter="BtnQuery"></el-input>
                        </td>
                        <td align="right">姓名</td>
                        <td>
                            <el-input v-model="searchobj.txtpatname" @keyup.enter.native="FunQuery" style="width: 150px" clearable @keyup.native.enter="BtnQuery"></el-input>
                        </td>
                        <td align="right">病人类别</td>
                        <td>
                            <rm-ddl-common datatype="seccode" kindno="PT" dataname="病人来源" v-model="searchobj.ddlpattype" width="160px" :clearable="true" @change="pattypeChange"></rm-ddl-common>
                        </td>
                        <td></td>
                        <td></td>
                    </tr>
                    <!-- <tr v-show="is_showselother">
                        <td align="right">报告单元</td>
                        <td colspan="3">
                            <rm-ddl-rptunit prgno="LIS972" :clearable="true" defaultflag="" v-model="searchobj.rptunitid" width="280px" key="1"></rm-ddl-rptunit>
                        </td>

                        <td align="right">检验仪器</td>
                        <td>
                            <rm-ddl-instrument v-model="searchobj.txtlabinstrument" width="180px" clearable></rm-ddl-instrument>
                        </td>
                        <td align="right">标本类型</td>
                        <td>
                            <el-select v-model="searchobj.txtspecimen" @dblclick.native="popMultipleChk(txtspecimen, 'txtspecimen', specimenOption, '标本类型选择')" filterable clearable style="width:180px">
                                <el-option v-for="(item, index) in specimenOption" :key="index" :value="item.data" :label="item.display"> </el-option>
                            </el-select>
                        </td>
                    </tr> -->
                </table>
                <div class="operation-list">
                    <el-button @click.native="BtnQuery" type="primary" icon="el-icon-search" v-has="'PINQUERY'">查询</el-button>
                    <el-button @click.native="BtnClear" icon="el-icon-close">清除</el-button>
                    <!-- <el-button @click.native="BtnPrint" icon="el-icon-printer">打印</el-button> -->
                    <el-button @click.native="BtnExport" icon="el-icon-download">导出</el-button>
                </div>
            </div>
        </div>
        <div :class="!is_showselother ? 'pagecenter' : 'pagecenterother'">
            <vxe-table :data.sync="labData" :select-config="{ reserve: true, checkAll: true }" :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row class="mytable-style" highlight-hover-column highlight-hover-row how-header-overflow ref="xTable" resizable show-overflow size="mini" stripe show-header-overflow :optimization="{ animat: false }" header-align="center" :loading="loading" @current-change="currentChangeEvent" :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: false }" :key="labDatakey">
                <!-- <vxe-table-column field="rechkflag" sortable title="审核" width="40" align="center">
                    <template v-slot="{ row }">
                        <span style="font-size: 16px; color: blue">{{ row.rechkflag == "9" ? "审" : "" }}</span>
                    </template>
                </vxe-table-column>
                <vxe-table-column field="alter_flag" sortable title="警告" width="40" align="center">
                    <template v-slot="{ row }">
                        <span style="color: blue; font-size: 16px">{{ row.alter_flag == "1" ? "警" : "" }}</span>
                    </template>
                </vxe-table-column>
                <vxe-table-column field="emer_flag" sortable title="加急" width="40" align="center">
                    <template v-slot="{ row }">
                        <span style="color: red; font-size: 16px">{{ row.emer_flag == "1" ? "急" : "" }}</span>
                    </template>
                </vxe-table-column>
                <vxe-table-column field="redo_flag" sortable title="复查" width="40" align="center">
                    <template v-slot="{ row }">
                        <span style="color: green; font-size: 16px">{{ row.redo_flag == "1" ? "复" : "" }}</span>
                    </template>
                </vxe-table-column>
                <vxe-table-column field="rptunitname" sortable title="报告单元" width="120">
                    <template v-slot="{ row }">
                        <span>{{ row.rptunitname +'['+row.rptunitid+']' }}</span>
                    </template>
                </vxe-table-column>

                <vxe-table-column field="result1" sortable title="菌落计数" width="70" align="center"></vxe-table-column>
                <vxe-table-column field="result4" sortable title="耐药机制" width="70"></vxe-table-column>
                <vxe-table-column field="instrid" sortable title="检验仪器" width="80" align="center"></vxe-table-column>
                <vxe-table-column field="result2" sortable title="特殊结果2" width="80" align="center"></vxe-table-column>
                <vxe-table-column field="rechk_username" sortable title="审核医生" width="70" align="center"></vxe-table-column>
                <vxe-table-column field="result_txt" sortable title="专家评语" width="90" align="center"></vxe-table-column>
                <vxe-table-column field="result3" sortable title="药敏组" width="90" align="center"></vxe-table-column>
                <vxe-table-column field="print_count" sortable title="打印次数" width="60" align="center"></vxe-table-column>
                <vxe-table-column field="charge_typeno" sortable title="收费类别" width="90"></vxe-table-column>
                <vxe-table-column field="pat_diag" sortable title="临床诊断" width="90"></vxe-table-column>
              <vxe-table-column field="input_dt" sortable title="录入时间" width="120" align="center"></vxe-table-column>
                <vxe-table-column field="test_info" sortable title="上机信息" width="90" align="center"></vxe-table-column>
                <vxe-table-column field="test_dt" sortable title="上机时间" width="120"></vxe-table-column>
                <vxe-table-column field="report_dt" sortable title="报告时间" width="120" align="center"></vxe-table-column>
                <vxe-table-column field="report_user" sortable title="检验医生姓名" width="90" align="center"></vxe-table-column>
                <vxe-table-column field="lab_advice" sortable title="实验室意见" width="100"></vxe-table-column> -->
                <!-- <vxe-table-column field="item_num" sortable title="项目数" width="60" align="center"></vxe-table-column> -->
                <!-- <vxe-table-column field="instr_advice" sortable title="仪器辅助诊断" width="100" align="center"></vxe-table-column>
                <vxe-table-column field="rechk2_dt" sortable title="二审时间" width="120" align="center"></vxe-table-column>
                <vxe-table-column field="rechk2_username" sortable title="二审医生" width="60" align="center"></vxe-table-column>
                <vxe-table-column field="lastprint_dt" sortable title="最后打印时间" width="120" align="center"></vxe-table-column>
                <vxe-table-column field="charge_flag" sortable title="计价" width="50" align="center" :edit-render="{ name: 'select', options: $opt.chargeOption }"></vxe-table-column><vxe-table-column field="prereport_dt" sortable title="预报告时间" width="120" align="center"></vxe-table-column>
                <vxe-table-column field="reportid" sortable title="报告ID" width="120"></vxe-table-column>
                <vxe-table-column field="hospname" sortable title="医院" width="120" align="center"></vxe-table-column>
                <vxe-table-column field="req_id" sortable title="申请单ID" width="80" align="center"></vxe-table-column>
                <vxe-table-column field="pat_cardno" sortable title="就诊卡号" width="100"></vxe-table-column>
                <vxe-table-column field="inp_id" sortable title="就诊号" width="100" align="center"></vxe-table-column>
                <vxe-table-column field="inp_date" sortable title="入院日期" width="120" align="center"></vxe-table-column> -->
                <vxe-table-column field="pat_no" sortable title="病历号" width="70"></vxe-table-column>
                <vxe-table-column field="pat_name" sortable title="姓名" width="50" align="center"></vxe-table-column>
                <vxe-table-column field="pat_sex" sortable title="性别" width="40" align="center" :edit-render="{ name: 'select', options: $opt.patSex }"></vxe-table-column>
                <vxe-table-column field="pat_agestr" sortable title="年龄" width="50" align="center"></vxe-table-column>
                <vxe-table-column field="pat_typename" sortable title="病人类别" width="60" align="center"></vxe-table-column>
                <!-- <vxe-table-column field="pat_id" sortable title="病人ID" width="100"></vxe-table-column> -->
                <vxe-table-column field="req_dt" sortable title="申请时间" width="120" align="center"></vxe-table-column>
                <vxe-table-column field="req_docno" sortable title="申请医生" width="70" align="center"></vxe-table-column>
                <vxe-table-column field="req_deptname" sortable title="申请科室" width="100"></vxe-table-column>
                <vxe-table-column field="req_bedno" sortable title="床号" width="60" align="center"></vxe-table-column>
                <vxe-table-column field="pat_phone" sortable title="联系电话" width="80" align="center"></vxe-table-column>
                <vxe-table-column field="req_wardname" sortable title="病人病区" width="90"></vxe-table-column>
                <vxe-table-column field="barcode" sortable title="条码号" width="90" align="center"></vxe-table-column>
                <vxe-table-column field="report_comm" sortable title="报告单备注" width="100" align="center"></vxe-table-column>
                <vxe-table-column field="req_reason" sortable title="送检目的" width="120"></vxe-table-column>
                <vxe-table-column field="sampled_dt" sortable title="采样时间" width="120"></vxe-table-column>
                <vxe-table-column field="collectionpointname" sortable title="采集部位" width="80" align="center"></vxe-table-column>
                <vxe-table-column field="specimen_comm" sortable title="标本状态备注" width="80" align="center"></vxe-table-column>
                <vxe-table-column field="specimen_name" sortable title="标本类型" width="80" align="center"></vxe-table-column>
                <vxe-table-column field="rechk_dt" sortable title="审核时间" width="120" align="center"></vxe-table-column>
                <vxe-table-column field="recieve_dt" sortable title="接收时间" width="120" align="center"></vxe-table-column>
                <vxe-table-column field="sampledate" sortable title="标本日期" width="80" align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                <vxe-table-column field="sampleno" sortable title="标本号" width="80" align="center"></vxe-table-column>
                <vxe-table-column field="rpt_itemcode" sortable title="项目代码" width="80"></vxe-table-column>
                <vxe-table-column field="rpt_itemname" sortable title="培养结果/检验项目" width="150"></vxe-table-column>
                <!-- <vxe-table-column field="lastmodify_dt" sortable title="最后修改时间" width="120" align="center"></vxe-table-column> -->
                <!-- <vxe-table-column field="release_dt" sortable title="发布时间" width="120" align="center"></vxe-table-column>
                <vxe-table-column field="release_user" sortable title="发布人" width="70" align="center"></vxe-table-column>
                <vxe-table-column field="is_changed" sortable title="是否修改" width="70" align="center"></vxe-table-column> -->
                <!-- <vxe-table-column field="changed_afterreport" sortable title="打印、审核后修改" width="100" align="center"></vxe-table-column> -->
                <!-- <vxe-table-column field="unprint_flag" sortable title="禁止打印标志" width="100" align="center"></vxe-table-column>
                <vxe-table-column field="unprint_reason" sortable title="禁止打印原因" width="100" align="center"></vxe-table-column> -->
                <vxe-table-column :field="items.field" :key="index" :title="items.title" sortable v-for="(items,index) in LabDataCol" :width="items.width" :align="items.align" header-align="center"></vxe-table-column>
                <template v-slot:fix>
                    <div style="font-size: 17px; text-align: center; background-color: #fff; color: blue">
                        <span>共{{ rowcount }}行</span>
                    </div>
                </template>
            </vxe-table>
        </div>
        <!--多选弹窗--->
        <el-dialog width="900px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :title="multichktitle" :visible.sync="dialogMultipleVisible" :destroy-on-close="true">
            <rm-SqlMultiple :leftOption="option1" :rightOption="option2" :name="fieldname" @change="closedialog"></rm-SqlMultiple>
        </el-dialog>
    </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
import axios from "axios";
export default {
    name: "LIS972",
    data() {
        return {
            searchobj: {
                strdate: this.$pub.InitDate(),
                enddate: this.$pub.InitDate(),
                onlyposresult: "1",
            },
            exportobj: {},
            labData: [],
            labDatakey: 0,
            lab_resultmedData: [],
            loading: false,
            is_showselother: false,
            datename: "标本日期",
            datetype: "1",
            pattypeOption: [],
            deptOption: [],
            wardOption: [],
            hospOption: [],
            germOption: [],
            rptunitOption: [],
            specimenOption: [],
            doctorOption: [],
            userOption: [],
            instrOption: [],
            LabDataCol: [],
            option1: [],
            option2: [],
            dialogMultipleVisible: false,
            multichktitle: "",
            fieldname: "",
            germgroupname: "",
            germkindname: "",
            pattypename: "",
        };
    },
    created() {
        this.initOption();
    },
    computed: {
        rowcount() {
            return this.labData.length;
        },
    },
    mounted() {},
    methods: {
        popMultipleChk(e, fieldname, option, title) {
            let temp = XEUtils.clone(option, true);
            this.option1 = [];
            this.option2 = [];
            if (!!e) {
                let k = e.split(",");
                k.forEach((item) => {
                    let ndata = temp.find((m) => m.data == item);
                    if (ndata != undefined && ndata != null) {
                        this.option2.push(ndata);
                    }
                });
                temp.forEach((item) => {
                    if (k.indexOf(item.data + "") < 0) {
                        this.option1.push(item);
                    }
                });
            } else {
                this.option1 = temp;
            }
            this.fieldname = fieldname;
            this.multichktitle = title;
            this.dialogMultipleVisible = true;
        },
        closedialog(value, name) {
            if (value != "close") {
                this.searchobj[name] = value;
            }
            this.dialogMultipleVisible = false;
        },
        initOption() {
            this.$tool
                .request({
                    url: "LIS/LIS9/LIS972",
                    method: "post",
                    data: {
                        action: "initOption",
                    },
                })
                .then((res) => {
                    this.deptOption = res.deptOption;
                    this.germOption = res.germOption;
                })
                .catch((e) => {
                    this.$alert(e, "提示");
                });
        },
        BtnQuery() {
            this.loading = true;
            this.$tool
                .request({
                    url: "LIS/LIS9/LIS972",
                    method: "post",
                    data: {
                        action: "query",
                        daytype: this.datetype,
                        ...this.searchobj,
                    },
                })
                .then((response) => {
                    if (response.errcode == "1") {
                        this.labData = response.RData.Data;
                        this.LabDataCol = response.RData.Cols;
                        if (this.labData.length > 0) this.is_showselother = false;
                    } else {
                        this.$alert(response.errmsg, "提示");
                        this.labData = [];
                        this.LabDataCol = [];
                    }
                    this.labDatakey++;
                    this.loading = false;
                })
                .catch((e) => {
                    this.$alert(e, "出错");
                    this.loading = false;
                });
        },
        currentChangeEvent({ row }) {},
        BtnClear() {
            this.searchobj = {
                strdate: this.$pub.InitDate(),
                enddate: this.$pub.InitDate(),
                onlyposresult: "1",
            };
            this.labData = [];
            this.LabDataCol = [];
        },
        germgroupChange(code, name) {
            this.searchobj.germgroup = code;
            this.germgroupname = name;
        },
        germkindChange(code, name) {
            this.searchobj.germkind = code;
            this.germkindname = name;
        },
        pattypeChange(code, name) {
            this.searchobj.ddlpattype = code;
            this.pattypename = name;
        },
        BtnExport() {
            let tableColumn = this.$refs.xTable.getColumns();
            let extableColumn = [];
            tableColumn.forEach((item) => {
                extableColumn.push({ title: item.title, field: item.property });
            });
            let filtertxt = this.getExportFilter();
            this.$pub.exportTableExcel(this.labData, extableColumn, "LIS972细菌药敏结果查询.xlsx", filtertxt);
        },
        // 获取当前导出文件的所有查询条件
        getExportFilter() {
            let filtertxt = this.datename + ":" + XEUtils.toDateString(this.searchobj.strdate, "yyyy-MM-dd") + "至" + XEUtils.toDateString(this.searchobj.enddate, "yyyy-MM-dd") + "; ";
            if(this.searchobj.germgroup) filtertxt += "菌属:" + this.germgroupname + "; ";
            if(this.searchobj.germkind) filtertxt += "菌科:" + this.germkindname + "; ";
            if(this.searchobj.germrptitemcode) filtertxt += "细菌:" + this.getOptionName(this.germOption.filter((item) =>  ("," + this.searchobj.germrptitemcode + ",").indexOf("," + item.data + ",") > -1)) + "; ";
            if(this.searchobj.result_min) filtertxt += "数值结果<:" + this.searchobj.result_min + "; ";
            if(this.searchobj.result_max) filtertxt += "数值结果>:" + this.searchobj.result_max + "; ";
            if(this.searchobj.onlyposresult == "1") filtertxt += "包含药敏; ";
            if(this.searchobj.txtbarcode) filtertxt += "标本号:" + this.searchobj.txtbarcode + "; ";
            if(this.searchobj.reqdept) filtertxt += "科室:" + this.getOptionName(this.deptOption.filter((item) =>  ("," + this.searchobj.reqdept + ",").indexOf("," + item.data + ",") > -1)) + "; ";
            if(this.searchobj.txtpatno) filtertxt += "病历号:" + this.searchobj.txtpatno + "; ";
            if(this.searchobj.txtpatname) filtertxt += "姓名:" + this.searchobj.txtpatname + "; ";
            if(this.searchobj.ddlpattype) filtertxt += "病人类别:" + this.pattypename + "; ";
            return filtertxt;
        },
        getOptionName(option) {
            if (option && option.length > 0) {
                let optionname = "";
                option.forEach((item) => {
                    if(item.hasOwnProperty("display")) {
                        optionname += item.display + ",";
                    } else {
                        optionname += item.label + ",";
                    }
                });
                return optionname.substring(0, optionname.length - 1);
            } else {
                return "";
            }
        },
        btn_showselother() {
            this.is_showselother = !this.is_showselother;
        },
        handleCommand(name) {
            this.datename = name;
            if (name == "标本日期") {
                this.datetype = "1";
            } else {
                this.datetype = "2";
            }
        },
        ExportConditionSure() {
            this.exportConditionVisible = false;
        },
    },
};
</script>

<style scoped>
.pagetop {
    width: 100%;
    height: 70px;
    display: -webkit-box;
    -webkit-box-pack: left;
    -webkit-box-align: center;
    border: 1px solid #ccc;
    position: absolute;
    z-index: 99;
    overflow-x: auto;
    overflow-x: overlay;
}
.pagetopother {
    width: 100%;
    height: 100px;
    display: -webkit-box;
    -webkit-box-pack: left;
    -webkit-box-align: center;
    border: 1px solid #ccc;
    position: absolute;
    z-index: 99;
    overflow-x: auto;
    overflow-x: overlay;
}
.pagecenter {
    position: absolute;
    top: 75px;
    width: 100%;
    left: 0;
    bottom: 0px;
    overflow: auto;
}
.pagecenterother {
    position: absolute;
    top: 105px;
    width: 100%;
    left: 0;
    bottom: 0px;
    overflow: auto;
}
.operation-list {
    float: right;
    margin-right: 5px;
    margin-bottom: 5px;
}
table {
    font-size: 12px;
    border-collapse: separate;
    border-spacing: 5px;
}
.el-input--suffix .el-input__inner {
    padding-right: 0px;
}
::-webkit-scrollbar {
    width: 0px;
    height: 5px;
    border: 4px solid white;
}
::-webkit-scrollbar-thumb {
    background-color: #c1c1c1;
}
::-webkit-scrollbar-track {
    background-color: #f1f1f1;
}
</style>
